<script setup lang="ts">
import {onMounted, ref} from 'vue'
import axios from 'axios'
import VPLink from '../common/vp-link.vue'
import VPMarkdown from '../common/vp-markdown.vue'
import {useLang} from '../../composables/lang'
import {useLocale} from '../../composables/locale'
import changelogLocale from '../../i18n/component/changelog.json'

interface Release {
  id: number
  name: string
}

const loading = ref(true)
const releases = ref<Release[]>([])
const currentRelease = ref()
const changelog = useLocale(changelogLocale)
const lang = useLang()

const onVersionChange = (val) => {
  const _releases = releases.value
  currentRelease.value = _releases[_releases.findIndex((r) => r.name === val)]
}

onMounted(async () => {
  try {
    const {data} = await axios.get<Release[]>(
        'https://api.gitee.com/repos/zeitlmz/ikun-plus/releases'
    )
    releases.value = data
    currentRelease.value = data[0]
  } catch {
    releases.value = []
    currentRelease.value = undefined
    // do something
  } finally {
    loading.value = false
  }
})
</script>
<template>
  <div class="changelogs">
    <ClientOnly>
      <div class="changelog-versions">

      </div>

      <div>
        <VPMarkdown :content="currentRelease.body"/>
      </div>
    </ClientOnly>
  </div>
</template>

<style lang="scss" scoped>
.changelog-versions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;

  p {
    margin-right: 2rem;
  }
}

.changelog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;

  .changelog-meta {
    display: flex;
    flex: 1;
    flex-direction: column;

    p {
      margin: 0;
    }
  }

  .link-item {
    line-height: 1.7;
  }
}
</style>
